//
//  GYWebViewViewController.m
//  GoodLuck
//
//  Created by apple on 2018/4/9.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYWebViewViewController.h"

@interface GYWebViewViewController ()<UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;

@end

@implementation GYWebViewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    ///self.navigationItem.title = @"网页";
    NSURLRequest *request = [NSURLRequest requestWithURL:self.url];
    [self.webView loadRequest:request];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [EasyLodingView hidenLoding];
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    [EasyLodingView showLodingText:@"加载中..."];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [EasyLodingView hidenLoding];
    
    //获取网页的标题作为导航栏的标题
    NSString *title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    if (title.length != 0) {
        self.navigationItem.title = title;
    }else {
        self.navigationItem.title = @"客服";
    }
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    NSLog(@"error=====%@",error);
    [EasyLodingView hidenLoding];
    [EasyTextView showText:@"加载出错,请重新加载!"];
}
@end
